package com.longge;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-03-08 23:55
 */
public class BtreeGameWinningMove {
    int l, r;

    public boolean btreeGameWinningMove(TreeNode root, int n, int x) {
        dfs(root,x);
        int o = n - l - r - 1;
        return o > n / 2 || l > n / 2 || r > n / 2;
    }

    private int dfs(TreeNode root, int x) {
        if (root == null) return 0;
        int l = dfs(root.left, x);
        int r = dfs(root.right, x);
        if (root.val == x) {
            this.l = l;
            this.r = r;
        }
        return l + r + 1;
    }

    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(1);
        TreeNode treeNode2 = new TreeNode(2);
        TreeNode treeNode3 = new TreeNode(3);
        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;
        new BtreeGameWinningMove().btreeGameWinningMove(treeNode1,3,1);
    }
}
